﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using GurLoader.View;
using Moq;
using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace GurLoaderWPF.Test.View
{
    [TestFixture]
    public class WebBrowserBehaviorsTests
    {
        [Test]
        public void GetBindableSourcceTest()
        {
            DependencyObject d = new DependencyObject();
            object testsource = new object();

            Assert.IsNull(d.GetValue(WebBrowserBehaviors.BindableSourceProperty));

            WebBrowserBehaviors.SetBindableSource(d, testsource);
            Assert.AreEqual(testsource, WebBrowserBehaviors.GetBindableSource(d));
        }

        [Test]
        public void SetBindableSourceTest()
        {
            DependencyObject d = new DependencyObject();
            object testsource = new object();

            WebBrowserBehaviors.SetBindableSource(d, testsource);
            Assert.AreEqual(testsource, d.GetValue(WebBrowserBehaviors.BindableSourceProperty));
        }

        [Test]
        public void BindableSourcePropertyChangedStringTest()
        {
            Mock<IWebBrowser> mockBrowser = new Mock<IWebBrowser>();
            string testSource = "http://www.something.com";

            DependencyPropertyChangedEventArgs args = new DependencyPropertyChangedEventArgs(
                WebBrowserBehaviors.BindableSourceProperty, null, testSource);

            mockBrowser.SetupSet(x=>x.Source = new Uri(testSource) ).Verifiable();

            WebBrowserBehaviors.BindableSourcePropertyChanged(mockBrowser.Object, args);

            mockBrowser.VerifyAll();
        }

        [Test]
        public void BindableSourcePropertyChangedStringEmptyTest()
        {
            Mock<IWebBrowser> mockBrowser = new Mock<IWebBrowser>();
            string testSource = "";

            DependencyPropertyChangedEventArgs args = new DependencyPropertyChangedEventArgs(
                WebBrowserBehaviors.BindableSourceProperty, null, testSource);

            WebBrowserBehaviors.BindableSourcePropertyChanged(mockBrowser.Object, args);

            mockBrowser.VerifyAll();
        }

        [Test]
        public void BindableSourcePropertyChangedNullBrowserTest()
        {
            string testSource = "http://www.something.com";

            DependencyPropertyChangedEventArgs args = new DependencyPropertyChangedEventArgs(
                WebBrowserBehaviors.BindableSourceProperty, null, testSource);

            WebBrowserBehaviors.BindableSourcePropertyChanged((IWebBrowser) null, args);
        }

        [Test]
        public void BindableSourcePropertyChangedUriTest()
        {
            Mock<IWebBrowser> mockBrowser = new Mock<IWebBrowser>();
            Uri testSource =  new Uri("http://www.something.com");

            DependencyPropertyChangedEventArgs args = new DependencyPropertyChangedEventArgs(
                WebBrowserBehaviors.BindableSourceProperty, null, testSource);

            mockBrowser.SetupSet(x => x.Source = testSource).Verifiable();

            WebBrowserBehaviors.BindableSourcePropertyChanged(mockBrowser.Object, args);

            mockBrowser.VerifyAll();
        }

        [Test]
        public void BindableSourcePropertyChangedOtherObjectTest()
        {
            Mock<IWebBrowser> mockBrowser = new Mock<IWebBrowser>();
            int testSource = 7;

            DependencyPropertyChangedEventArgs args = new DependencyPropertyChangedEventArgs(
                WebBrowserBehaviors.BindableSourceProperty, null, testSource);

            WebBrowserBehaviors.BindableSourcePropertyChanged(mockBrowser.Object, args);

            mockBrowser.VerifyAll();
        }
    }
}
